<template>
    <div class="wrapper">
        <el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
            <el-form-item label="手机号" prop="phoneNum">
                <el-input type="text" v-model="ruleForm.phoneNum" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码" prop="passNum">
                <el-input type="password" v-model="ruleForm.passNum" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>
import request from '../untils/request'
export default {
    data(){
        return {
            ruleForm: {
                phoneNum: '',
                passNum: '',
            },
            rules: {
                phoneNum: [
                    { required: true, message: '手机号不可以为空', trigger: 'change' }
                ],
                passNum: [
                    { required: true, message: '密码不可以为空', trigger: 'change' }
                ],
            }
        }
    },
    methods: {
      submitForm(formName) {
        this.$refs[formName].validate((valid) => {
          if (valid) {
              request.post(`/user/register/`, this.ruleForm).then(res => {
                 if(res.msg == '注册成功'){
                    this.$message.success('注册成功')
                    window.setTimeout(() => {
                        this.$router.push({
                            name: 'Login'
                        })
                    }, 500)
                 } else {
                    this.$message.warning(res.msg)
                 }
              })
          } else {
            alert('error submit!!');
            return false;
          }
        });
      },
    }
}
</script>
<style>

</style>